package datamodel;

import java.util.ArrayList;
import java.util.List;

import communication.Client;
import communication.ServiceCommunicator;
import communication.Type;

public class ClientHelper {
	public static List<String> getHTTPMethods(Client client) {
		List<String> methods = new ArrayList<String>();
		for (ServiceCommunicator communicator : client.getMethods()) {
			String method = communicator.getUseServices().getHttpMethod();
			if (!methods.contains(method)) {
				methods.add(method);
			}
		}
		return methods;
	}

	public static List<Type> getDataTransferObjects(Client client) {
		List<Type> dtos = new ArrayList<Type>();
		for (ServiceCommunicator communicator : client.getMethods()) {
			Type dto = communicator.getUseServices().getResponse();
			boolean isContains = isContains(dtos, dto);
			if (isContains == true)
				dtos.add(dto);
		}
		return dtos;
	}

	private static boolean isContains(List<Type> dtos, Type dto) {
		boolean isContains = false;
		for (Type type : dtos) {
			if(type.getName().equals(dto.getName()))
			{
				isContains = true;
				break;
			}
		}
		return isContains;
	}
}
